import java.util.Scanner;

public class if4{
    public static void main(String[] args) {
        // 产生中奖整数
        int winningNumber = (int) (Math.random() * 90 + 10);

        // 提示用户输入
        System.out.println("欢迎参加猜数游戏！请输入一个两位数：");
        Scanner scanner = new Scanner(System.in);
        int userNumber = scanner.nextInt();

        // 判断奖励
        int reward = calculateReward(winningNumber, userNumber);
        System.out.println("您的奖金为：" + reward + "元");
    }

    // 判断奖励方法
    public static int calculateReward(int winningNumber, int userNumber) {
        if (winningNumber == userNumber) {
            return 10000;
        } else if (isExactMatch(winningNumber, userNumber)) {
            return 2000;
        } else if (isPartialMatch(winningNumber, userNumber)) {
            return 1000;
        } else if (isNonSequentialMatch(winningNumber, userNumber)) {
            return 500;
        } else {
            return 0;
        }
    }

    // 判断是否完全匹配
    public static boolean isExactMatch(int winningNumber, int userNumber) {
        return winningNumber == userNumber;
    }

    // 判断是否部分匹配
    public static boolean isPartialMatch(int winningNumber, int userNumber) {
        String winningString = Integer.toString(winningNumber);
        String userString = Integer.toString(userNumber);

        for (int i = 0; i < 2; i++) {
            if (winningString.contains(String.valueOf(userString.charAt(i)))) {
                winningString = winningString.replaceFirst(String.valueOf(userString.charAt(i)), "");
                userString = userString.replaceFirst(String.valueOf(userString.charAt(i)), "");
            } else {
                return false;
            }
        }

        return true;
    }

    // 判断是否非顺序匹配
    public static boolean isNonSequentialMatch(int winningNumber, int userNumber) {
        String winningString = Integer.toString(winningNumber);
        String userString = Integer.toString(userNumber);

        for (int i = 0; i < 2; i++) {
            if (winningString.contains(String.valueOf(userString.charAt(i)))) {
                userString = userString.replaceFirst(String.valueOf(userString.charAt(i)), "");
            } else {
                return false;
            }
        }

        return true;
    }
}
